package com.dk.controller;


import com.dk.model.Work;
import com.dk.service.WorkService;
import com.dk.vo.WorkVO;
import com.dongdongshop.data.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wbh
 * @since 2023-03-17
 */
@RestController
@RequestMapping("work")
public class WorkController {
    @Autowired
    private WorkService workService;
    /*
    *   1.模糊查询 编号,名称,单据来源,产品编号,产品名称,客户编码,客户名称,需求日期
    *   将客户表的id与name家到字段中,就不需要去联表查询了
    * */

    //查询全部的接口,根据三级分类去查询的接口
    @GetMapping("getAllByPid")
    public Result getAll(WorkVO workVO){
        List<WorkVO> workVOList = workService.getAll(workVO);
        return Result.OK().setData(workVOList);
    }

    /**
     *
     * @param workVO 需要的参数 前台获取到订单来源,如果是客户订单则有订单的id 若为库存需要,没有订单id
     *
     * @return
     */

    @PostMapping("insertInfoWork")
    public Result insertInfoWork(WorkVO workVO){
        workService.insertInfoWork(workVO);
        return Result.OK();
    }

    //修改查询
    @PostMapping("updateByWorkId")
    public Result updateByWorkId(@RequestParam String workId){
        Work work = workService.updateByWorkId(workId);
        return Result.OK().setData(work);
    }


    @PostMapping("updateInfoWork")
    public Result updateInfoWork(WorkVO workVO){
        workService.updateInfoWork(workVO);
        return Result.OK();
    }

    //删除
    @PostMapping("deleteInfoWork")
    public Result deleteInfoWork(String workId){
        workService.deleteInfoWork(workId);
        return Result.OK();
    }
}

